package com.sky.controller.user;

import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "套餐接口")
@RestController("userSetMealController")
@RequestMapping("/user/setmeal")
@Slf4j
public class SetMealController {
    @Autowired
    private SetMealService setMealService;

    @Cacheable(cacheNames = "setMeal", key = "#categoryId")
    @ApiOperation("分类id获取套餐")
    @GetMapping("/list")
    public Result<List<Dish>> getSetMealList(@RequestParam Long categoryId) {
        List<Dish> dishList = setMealService.selectSetMealByCategoryId(categoryId);

        return Result.success(dishList);
    }


    @ApiOperation("套餐id获取关联商品")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getSetMealDishBySetMealId(@PathVariable Long id) {
        List<DishItemVO> dishItemVOList = setMealService.getSetMealDishBySetMealId(id);

        return Result.success(dishItemVOList);
    }
}
